package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"mxshop_srvs/inventory_srv/proto"
)

var conn *grpc.ClientConn
var client proto.InventoryClient
var err error

func main() {

	Init()
	//testSetInv()
	//testAddStock()
	testInvDetail()
	conn.Close()
}

func Init() {
	conn, err = grpc.Dial("10.26.10.121:50156", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}
	client = proto.NewInventoryClient(conn)
}

func testSell() {

	_, er := client.Sell(context.Background(), &proto.SellInfo{
		GoodsInfo: []*proto.GoodsInvInfo{
			{GoodsId: 9, Num: 10},
			{GoodsId: 10, Num: 10},
		},
	})
	if er != nil {
		panic(er)
	}
}

func testInvDetail() {
	detail, err2 := client.InvDetail(context.Background(), &proto.GoodsInvInfo{
		GoodsId: 9,
	})
	if err2 != nil {
		panic(err2)
	}
	fmt.Println(detail)
}

func testSetInv() {
	_, err2 := client.SetInv(context.Background(), &proto.GoodsInvInfo{
		GoodsId: 9,
		Num:     100,
	})
	if err2 != nil {
		panic(err2)
	}
}

func testAddStock() {
	for i := 10; i < 17; i++ {
		client.SetInv(context.Background(), &proto.GoodsInvInfo{
			GoodsId: int32(i),
			Num:     100,
		})
	}
}
